/*
	Twitch
	Please leave credits to the origional devs where its due if edited.
*/

GM.Weapons = {}
GM.Projectiles = {}

function GM:RegisterWeapon(name,func)
	if !name or type(func) != "function" then return end
	self.Weapons[name] = func
end

function GM:GetWeaponFunction(name)
	return self.Weapons[name]
end

function GM:RegisterProjectile(name,speed,init,hit,draw)
	self.Projectiles[name] = {Spee = speed,Init = init,Hit = hit,Draw = draw}
end

function GM:GetProjectile(name)
	return self.Projectiles[name]
end

GM:RegisterWeapon("Plasma Cannon",
	function(self) // Shoot function (Called when the ship fires).
		if SERVER then
			if self:Energy() >= 0.5 then
				local e = ents.Create("twc_projectile")
				e:SetPos(self:GetPos()+((self:GetForward()*2)*self:GetSpeed()))
				e:SetAngles(self:GetAngles())
				e:SetOwner(self:GetPlayer())
				e:SetProjectile("Plasma Projectile")
				e:Spawn()
				e:Activate()
				self:SetEnergy(self:Energy()-math.Rand(0.2,0.5))
				self.NextEnergyGenerate = CurTime()+4
			end
		end
		return 0.2
	end
)

local Mat
if CLIENT then
	Mat = Material("sprites/glow04_noz")
end

GM:RegisterProjectile("Plasma Projectile",1600,
	function(self) // Init function (Called when the projectile is created).
		self:SetModel("models/Items/combine_rifle_ammo01.mdl")
	end,
	function(self,data,physobj) // Hit function (Called when hitting an object).
		data.HitEntity:TakeDamage(10,self:GetOwner(),self)
		self:Remove()
		return
	end,
	function(self) // Draw function (Called when drawing the projectile).
		render.SetMaterial(Mat)
		render.DrawSprite(self:GetPos()+(self:GetVelocity()/2)*(0*-0.01),16,16,Color(255,180,255,255))
	end
)
